package com.apes.fn.fico.debitnote.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.finance.model.PaymentMethodType;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 还款记录
 * Creator: zouyc
 * CreateDate: 2019-12-20 10:20
 * Description:
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = DebitRate.CONST_TABLE_NAME)
public class RepaymentRecord extends Model{
    public static final String CONST_TABLE_NAME = "fn_repaymentrecord";

    @Id
    @Column(name = "id", length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "还款记录编码", padding = 10)
    @Comment("还款记录编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "business_debit_note_id", referencedColumnName = "id", nullable = false)
    @Comment("借支单号")
    private BusinessDebitNote businessDebitNote;

    @Column(name = "before_capital_balance", columnDefinition = "NUMBER(16,2) DEFAULT 0")
    @Comment("还款前本金余额")
    private double beforeCapitalBalance = 0.0;

    @Column(name = "before_interest_balance", columnDefinition = "NUMBER(16,2)DEFAULT 0")
    @Comment("还款前利息余额")
    private double beforeInterestBalance = 0.0;

    @Column(name = "price_repayment", columnDefinition = "NUMBER(16,2)DEFAULT 0")
    @Comment("本次还款金额")
    private double priceRepayment = 0.0;

    @Column(name = "after_capital_balance", columnDefinition = "NUMBER(16,2) DEFAULT 0")
    @Comment("还款后本金余额")
    private double afterCapitalBalance = 0.0;

    @Column(name = "after_interest_balance", columnDefinition = "NUMBER(16,2)DEFAULT 0")
    @Comment("还款后利息余额")
    private double afterInterestBalance = 0.0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "payment_method_type_id", referencedColumnName = "id", nullable = false)
    @Comment("收款方式")
    private PaymentMethodType paymentMethodType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "repayment_uid", referencedColumnName = "id")
    @Comment("还款人")
    private PartyRole repaymentUid;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "repayment_date")
    @Comment("还款日期")
    private Date repaymentDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "payee_uid", referencedColumnName = "id")
    @Comment("收款人")
    private PartyRole payee;
}
